RichTextBox for WinRT
Step 2 of 4: Adding Resource Files and Code

In the previous step, you set up your application and added controls. In this step, you'll add the necessary resource files and add some of the code that controls printing. In this step, you'll add a resource file that was installed with your ComponentOne Studio WinRT Edition Samples. You can find the samples in the Documents folder of your system:

C:\Users\YourUserName\Documents\ComponentOne Samples\WinRT XAML Phone\C1.Xaml.RichTextBox\CS\RichTextBoxSamples\Resources

  1. Right-click your application name in the Solution Explorer and select Add | New Folder from the context menu. Name the new folder Resources and click OK.
  2. Right-click the Resources folder and select Add | Existing Item from the context menu. Browse to the location of your Samples, and select dickens.htm from the RichTextBoxSamples\Resources folder. Click OK to add the file to your Resources folder.
  3. Select the dickens.htm file in the Solution Explorer and set the Build Action property to Embedded Resource in the Properties window. Rebuild your application.
  4. Right-click your application page; select View Code from the context menu. The MainPage.xaml.cs page will open.
  5. Import the following namespaces:
C#
Copy Code
using Windows.UI.Xaml.Printing;
using C1.Xaml.RichTextBox;
using Windows.UI.ViewManagement;
using Windows.Graphics.Printing;
using System.Reflection;
using Windows.UI.Popups;
  1. Edit the MainPage class so that it resembles the following code:
C#
Copy Code
public sealed partial class MainPage : Page
    {
        /// <summary>
        /// PrintDocument is used to prepare the pages for printing.
        /// Prepare the pages to print in the handlers for the Paginate, GetPreviewPage, and AddPages events.
        /// </summary>
        protected PrintDocument printDocument = null;
        /// <summary>
        /// Marker interface for document source
        /// </summary>
        protected IPrintDocumentSource printDocumentSource = null;
        /// <summary>
        /// A list of UIElements used to store the rtb pages.
        /// </summary>
        internal List<FrameworkElement> pages = null;
        /// <summary>
        /// Used for printing the document of C1RichTextBox.
        /// </summary>
        C1RichTextViewManager viewManager;
  1. Edit the MainPage() constructor so that it resembles the following code. Please remember to replace "YourApplicationName" in the GetManifestResourceStream() with your application name:
C#
Copy Code
public MainPage()
        {
            this.InitializeComponent();
            Assembly asm = typeof(MainPage).GetTypeInfo().Assembly;
            Stream stream = asm.GetManifestResourceStream("YourApplicationName.Resources.dickens.htm");
            var html = new StreamReader(stream).ReadToEnd();
            rtb.Html = html;
            pages = new List<FrameworkElement>();
            this.Loaded += Printing_Loaded;
            this.Unloaded += Printing_Unloaded;
        }

In this step, you added a Resources file, and the appropriate existing dickens.htm file. You also added code to the MainPage.xaml.cs file. In the next step, you'll add the rest of the code to handle the Button_Click event for the general Button control, and the Printing events that you added in the MainPage() constructor.    

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback